package com.chart.chart.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chart.chart.domian.ChartConfigs;
import com.chart.chart.domian.ChartConfigsAndViewsVo;
import com.chart.chart.domian.ChartConfigsUser;
import com.chart.chart.domian.req.UListReq;
import com.chart.chart.domian.vo.ChartConfigsUserVo;
import com.chart.chart.mapper.ChartConfigsMapper;
import com.chart.chart.mapper.ChartConfigsUserMapper;
import com.chart.chart.service.IChartConfigsService;
import com.chart.chart.service.IChartConfigsUserService;
import com.chart.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

import static com.chart.common.utils.PageUtils.startPage;

/**
 * 用户 业务层处理
 *
 * @author ruoyi
 */
@Service
public class ChartConfigsUserServiceImpl extends ServiceImpl<ChartConfigsUserMapper, ChartConfigsUser> implements IChartConfigsUserService {
    @Autowired
    private ChartConfigsUserMapper chartConfigsUserMapper;



    @Autowired
    private  IChartConfigsUserService chartConfigsUserService;

    @Override
    public List<ChartConfigsUserVo> getListWithOutValue(ChartConfigsUserVo chartConfigsUserVo) {
        return chartConfigsUserMapper.getListWithOutValue(chartConfigsUserVo);
    }

    @Override
    public List<ChartConfigsAndViewsVo> getChartsAndViews(ChartConfigsUser configsUser) {
        startPage();
        List<ChartConfigsAndViewsVo> chartsAndViews = chartConfigsUserMapper.getChartsAndViews(configsUser);
        return chartsAndViews;
    }

    @Override
    public List<ChartConfigsAndViewsVo> getChartsAndViewsBathByFileIds(List<Long> ids) {
        return chartConfigsUserMapper.getChartsAndViewsBathByFileIds(ids);
    }

    @Override
    public boolean scatterChartfigsUser(List<ChartConfigsUser> collect) {
        return chartConfigsUserMapper.scatterChartfigsUser(collect);
    }

    @Override
    public List<ChartConfigsAndViewsVo> getChartsAndViewsBatch(ChartConfigsAndViewsVo chartConfigsAndViewsVo) {
        return chartConfigsUserMapper.getChartsAndViewsBatch(chartConfigsAndViewsVo);
    }

    @Override
    public List<ChartConfigsAndViewsVo> getInfoByName(ChartConfigsAndViewsVo chartConfigsAndViewsVo) {
        return chartConfigsUserMapper.getInfoByName(chartConfigsAndViewsVo);
    }

    @Override
    public List<ChartConfigsAndViewsVo> getFiles(ChartConfigsAndViewsVo chartConfigsAndViewsVo) {
        return chartConfigsUserMapper.getFiles(chartConfigsAndViewsVo);
    }

    @Override
    public boolean updateConfigTop(ChartConfigsUser chartConfigsUser) {
        return chartConfigsUserMapper.updateConfigTop(chartConfigsUser);
    }

    /**
     * 根据用户Id 文件名称 文件类型筛选
     *
     * @param userId
     * @param chartName
     * @param chartType
     * @return
     */

    @Override
    public List<ChartConfigsUser> getUsersExcludingChartValue(Long userId, String chartName, String chartType, Long subjectId, Long configId, Long sortOrder) {
        List<ChartConfigsUser> usersExcludingChartValue = chartConfigsUserMapper.getUsersExcludingChartValue(userId, chartName, chartType, subjectId, configId, sortOrder);
        return usersExcludingChartValue;


    }

    /**
     * 根据Id更新hot字段
     *
     * @param id
     * @return
     */
    @Override
    public boolean updateHotById(Long id) {
        int rows = chartConfigsUserMapper.updateHotById(id);
        return rows > 0;
    }

    @Override
    public ChartConfigsUser getOneByChartName(String chartName, Long userId) {
        return chartConfigsUserMapper.getOneByChartName(chartName, userId);

    }

    @Override
    public void updateRedisKey(Long id, String redisKey) {
        chartConfigsUserMapper.updateRedisKey(id, redisKey);
    }

    @Override
    public List<ChartConfigsAndViewsVo> getFiles1(ChartConfigsAndViewsVo chartConfigsAndViewsVo) {
        return chartConfigsUserMapper.getFiles1(chartConfigsAndViewsVo);
    }

    @Override
    public List<ChartConfigsAndViewsVo> getChartsAndViewsBatch1(ChartConfigsAndViewsVo chartConfigsAndViewsVo) {
        return chartConfigsUserMapper.getChartsAndViewsBatch1(chartConfigsAndViewsVo);
    }

    @Override
    public List<ChartConfigsAndViewsVo> getInfoByName1(ChartConfigsAndViewsVo chartConfigsAndViewsVo) {
        return chartConfigsUserMapper.getInfoByName1(chartConfigsAndViewsVo);
    }


    @Override
    public List<ChartConfigsUser> queryList(Long configId) {
        return chartConfigsUserMapper.queryList(configId);
    }


    public List<ChartConfigsUserVo> querychartConfigCount(UListReq req) {
        // 预处理参数：将空字符串转换为 null
        if (req.getChartConfigCount() != null && req.getChartConfigCount().toString().trim().isEmpty()) {
            req.setChartConfigCount(null);
        }
        if (req.getExportCount() != null && req.getExportCount().toString().trim().isEmpty()) {
            req.setExportCount(null);
        }

        List<ChartConfigsUserVo> chartConfigsUserVoList = chartConfigsUserMapper.querychartConfigCount(req);

        for (ChartConfigsUserVo chartConfigsUserVo : chartConfigsUserVoList) {
            String isVip = chartConfigsUserVo.getIsVip();
            if ("0".equals(isVip)) {
                chartConfigsUserVo.setIsVips("否");
            } else if ("1".equals(isVip)) {
                chartConfigsUserVo.setIsVips("是");
            }
        }
        return chartConfigsUserVoList;
    }
    /**
     *
     * @param req
     * @return
     */
    @Override
    public List<ChartConfigsUserVo> querychartConfigCount2(UListReq req) {
        List<ChartConfigsUser> list = chartConfigsUserService.list();




        return null;
    }




    @Override
    public List<ChartConfigsUser> queryPhotosByUserId(Long userId) {

        List<ChartConfigsUser> chartConfigsUsers = chartConfigsUserMapper.queryPhotosByUserId(userId);
        return chartConfigsUsers;
    }

}



